home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / misc / o-z / x-windows / mesa-amiwin / src / interp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  4.6 KB  |  199 lines

  1. /* interp.h */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Id: interp.h,v 1.6 1995/10/23 21:27:54 brianp Exp $
  26.  
  27. $Log: interp.h,v $
  28.  * Revision 1.6  1995/10/23  21:27:54  brianp
  29.  * new GLubyte interpolation using fixed point arithmetic
  30.  *
  31.  * Revision 1.5  1995/06/12  15:43:57  brianp
  32.  * separate GLint and GLubyte interpolation functions
  33.  *
  34.  * Revision 1.4  1995/06/02  13:59:01  brianp
  35.  * faster GL_INTERPOLATE() macro
  36.  *
  37.  * Revision 1.3  1995/05/22  20:59:34  brianp
  38.  * Release 1.2
  39.  *
  40.  * Revision 1.2  1995/03/04  19:25:29  brianp
  41.  * 1.1 beta revision
  42.  *
  43.  * Revision 1.1  1995/02/27  22:20:16  brianp
  44.  * Initial revision
  45.  *
  46.  */
  47.  
  48.  
  49. #ifndef INTERP_H
  50. #define INTERP_H
  51.  
  52.  
  53.  
  54. extern void gl_interpolate_i( GLint n, GLint y0, GLint y1, GLint yspan[] );
  55.  
  56.  
  57. extern void gl_interpolate_ub( GLint n, GLint y0, GLint y1, GLubyte yspan[] );
  58.  
  59.  
  60. extern void gl_interpolate_4ub( GLint n,
  61.                                 GLint a0, GLint a1, GLubyte aspan[],
  62.                                 GLint b0, GLint b1, GLubyte bspan[],
  63.                                 GLint c0, GLint c1, GLubyte cspan[],
  64.                                 GLint d0, GLint d1, GLubyte dspan[] );
  65.  
  66.  
  67. extern void gl_interp_texcoords( GLuint n,
  68.                  GLfloat eyez0, GLfloat eyez1,
  69.                  GLfloat winz0, GLfloat winz1,
  70.                  GLfloat s0, GLfloat s1,
  71.                  GLfloat t0, GLfloat t1,
  72.                  GLfloat s[], GLfloat t[], GLfloat *z );
  73.  
  74.  
  75. #ifdef DEBUG
  76.  
  77. #define GL_INTERPOLATE_I(N,Y0,Y1,YSPAN)   gl_interpolate_i(N,Y0,Y1,YSPAN)
  78.  
  79. #define GL_INTERPOLATE_UB(N,Y0,Y1,YSPAN)  gl_interpolate_ub(N,Y0,Y1,YSPAN)
  80.  
  81. #else
  82.  
  83. #define GL_INTERPOLATE_I(N,Y0,Y1,YSPAN)    \
  84. {                    \
  85.    switch (N) {                \
  86.       case 1:                \
  87.      YSPAN[0] = Y0;            \
  88.      break;                \
  89.       case 2:                \
  90.      YSPAN[0] = Y0;            \
  91.      YSPAN[1] = Y1;            \
  92.      break;                \
  93.       case 3:                \
  94.      YSPAN[0] = Y0;            \
  95.      YSPAN[1] = ((Y0)+(Y1)) >> 1;    \
  96.      YSPAN[2] = Y1;            \
  97.      break;                \
  98.       default:                \
  99.      if (Y0==Y1) {            \
  100.         register GLint i;        \
  101.         for (i=0;i<(N);i++) {    \
  102.            YSPAN[i] = Y0;        \
  103.         }                \
  104.      }                \
  105.      else {                \
  106.         register GLint i;        \
  107.         register GLint dx, dy;    \
  108.         register GLint a, b, d;    \
  109.         register GLint yy;        \
  110.         register GLint qa, qb;    \
  111.         dx = (N)-1;            \
  112.         dy = (Y1) - (Y0);        \
  113.         qa = dy / dx;        \
  114.         dy = dy % dx;        \
  115.         if (dy<0) {            \
  116.            dy = -dy;        \
  117.            qb = qa - 1;        \
  118.         }                \
  119.         else {            \
  120.            qb = qa + 1;        \
  121.         }                \
  122.         a = dy + dy;        \
  123.         d = a - dx;            \
  124.         b = d - dx;            \
  125.         yy = Y0;            \
  126.         for (i=0;i<(N);i++) {    \
  127.            YSPAN[i] = yy;        \
  128.            if (d<0) {        \
  129.           d += a;        \
  130.           yy += qa;        \
  131.            }            \
  132.            else {            \
  133.           d += b;        \
  134.           yy += qb;        \
  135.            }            \
  136.         }                \
  137.      }                \
  138.    }                    \
  139. }
  140.  
  141.  
  142.  
  143. #define GL_INTERPOLATE_UB(N,Y0,Y1,YSPAN)    \
  144.     if ((N)>1) {                \
  145.        int yy0 = (Y0) << 8;            \
  146.        int yy1 = (Y1) << 8;            \
  147.        int dyy = (yy1-yy0) / ((int)(N)-1);    \
  148.        int ii;                \
  149.        for (ii=0;ii<(N);ii++) {        \
  150.           YSPAN[ii] = yy0 >> 8;        \
  151.           yy0 += dyy;            \
  152.        }                    \
  153.     }                    \
  154.     else {                    \
  155.        YSPAN[0] = Y0;            \
  156.     }
  157.  
  158.  
  159.  
  160. #endif  /*DEBUG*/
  161.  
  162.  
  163.  
  164. #define GL_INTERPOLATE_4UB( N, A0,A1,A, B0,B1,B, C0,C1,C, D0,D1,D )    \
  165.     if ((N)<2) {                \
  166.        A[0] = A0;                \
  167.        B[0] = B0;                \
  168.        C[0] = C0;                \
  169.        D[0] = D0;                \
  170.     }                    \
  171.     else if ((N)==2) {            \
  172.        A[0] = A0;  A[1] = A1;        \
  173.        B[0] = B0;  B[1] = B1;        \
  174.        C[0] = C0;  C[1] = C1;        \
  175.        D[0] = D0;  D[1] = D1;        \
  176.     }                    \
  177.     else {                    \
  178.        int a0, da, b0, db, c0, dc, d0,dd;    \
  179.        int ii, nn = (int) (N) - 1;        \
  180.        a0 = (A0) << 8;            \
  181.        da = (((A1)<<8)-a0) / nn;        \
  182.        b0 = (B0) << 8;            \
  183.        db = (((B1)<<8)-b0) / nn;        \
  184.        c0 = (C0) << 8;            \
  185.        dc = (((C1)<<8)-c0) / nn;        \
  186.        d0 = (D0) << 8;            \
  187.        dd = (((D1)<<8)-d0) / nn;        \
  188.        for (ii=0;ii<(N);ii++) {        \
  189.           A[ii] = a0 >> 8;    a0+=da;        \
  190.           B[ii] = b0 >> 8;    b0+=db;        \
  191.           C[ii] = c0 >> 8;    c0+=dc;        \
  192.           D[ii] = d0 >> 8;    d0+=dd;        \
  193.        }                    \
  194.     }
  195.  
  196.  
  197. #endif  /* INTERP_H */
  198.  
  199.